package net.qiqbframework.event.dao.mpimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.qiqbframework.common.dto.PageResultDto;
import net.qiqbframework.eventsourcing.dao.DomainEventFeedbackDao;
import net.qiqbframework.eventsourcing.dao.DomainEventFeedbackPageCondition;
import net.qiqbframework.eventsourcing.dao.DomainEventFeedbackPo;
import net.qiqbframework.mp.BasicEntityPoDaoMpImpl;
import net.qiqbframework.mp.MpUtil;


import java.util.List;

public class DomainEventFeedbackDaoMpImpl extends BasicEntityPoDaoMpImpl<DomainEventFeedbackMapper, DomainEventFeedbackPo> implements DomainEventFeedbackDao {


    @Override
    public PageResultDto<DomainEventFeedbackPo> list4Page(DomainEventFeedbackPageCondition condition) {
        QueryWrapper<DomainEventFeedbackPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(DomainEventFeedbackPo::getEventId, condition.getEventId())
                .eq(condition.getStatus() != null, DomainEventFeedbackPo::getStatus, condition.getStatus())
                .like(StringUtils.isNotEmpty(condition.getProcessListenerId()), DomainEventFeedbackPo::getProcessListenerId, condition.getProcessListenerId())
                .like(StringUtils.isNotEmpty(condition.getProcessResultMsg()), DomainEventFeedbackPo::getProcessResultMsg, condition.getProcessResultMsg())
                .like(StringUtils.isNotEmpty(condition.getApplicationName()), DomainEventFeedbackPo::getApplicationName, condition.getApplicationName())
                .like(StringUtils.isNotEmpty(condition.getInstanceName()), DomainEventFeedbackPo::getInstanceName, condition.getInstanceName())

        ;
        final Page<DomainEventFeedbackPo> page = super.page(MpUtil.ofPage(condition), queryWrapper);
        return MpUtil.toResult(page);
    }

    @Override
    public List<DomainEventFeedbackPo> listByEventId(String eventId) {
        QueryWrapper<DomainEventFeedbackPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(DomainEventFeedbackPo::getEventId, eventId)

        ;
        return super.list(queryWrapper);
    }

}
